//
//  UIButton+Extension.swift
//  JXHSinaWeiBo
//
//  Created by juxiaohui on 16/10/14.
//  Copyright © 2016年 juxiaohui. All rights reserved.
//

import UIKit

extension UIButton {

    //扩展类方法
    
//  class func button(imageName : String, bgIamgeName : String) -> UIButton {
//    let btn = UIButton.init()
//    btn.setImage(UIImage.init(named: imageName), for: .normal)
//    btn.setImage(UIImage.init(named: imageName + "_highlighted"), for: .selected)
//    btn.setBackgroundImage(UIImage.init(named: bgIamgeName), for: .normal)
//    btn.setBackgroundImage(UIImage.init(named: bgIamgeName + "_highlighted"), for: .selected)
//    btn.sizeToFit()
//    return btn
//    }
//    
    
    //构造函数 （init）开头，不用写返回值，系统自动返回
    //convenience 修饰的构造函数，叫做便利函数，对系统的类便利扩充
    //1.通常写在extension里面
    //2.在便利构造函数需要明确调用 self.init()
    convenience init (imageName : String, bgIamgeName : String) {
        self.init()
        setImage(UIImage.init(named: imageName), for: .normal)
        setImage(UIImage.init(named: imageName + "_highlighted"), for: .selected)
        setBackgroundImage(UIImage.init(named: bgIamgeName), for: .normal)
        setBackgroundImage(UIImage.init(named: bgIamgeName + "_highlighted"), for: .selected)
        sizeToFit()
    }
}

